<template>
  <div class="city" v-if="hotCity">
    <!-- 热门城市 -->
    <p class="title">热门城市</p>
    <div
      class="hot-item"
      v-for="val in hotCity.cities"
      :key="val.cityId"
      @click="choose(val)"
    >
      {{ val.name }}
    </div>

    <!-- 其他城市 -->
    <div class="abc" v-for="item in otherCity" :key="item.prefix">
      <p class="title">{{ item.prefix }}</p>
      <div
        class="city-item"
        v-for="val in item.cities"
        :key="val.cityId"
        @click="choose(val)"
      >
        {{ val.name }}
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapActions, mapGetters } from "vuex";
export default {
  computed: mapGetters("city", ["hotCity", "otherCity"]),
  mounted() {
    this.asyncGetCityList();
  },
  methods: {
    choose(val) {
      this.changename(val);
      this.$router.push("/home");
    },
    ...mapMutations("city", ["changename"]),
    ...mapActions("city", ["asyncGetCityList"]),
  },
};
</script>

<style lang="less" scoped>
.title {
  background-color: #ebebeb;
  font-size: 0.28rem;
  color: #333;
  width: 100%;
  padding-left: 0.5rem;
  line-height: 0.6rem;
}

.hot-item {
  float: left;
  background: #fff;
  width: 29%;
  height: 0.66rem;
  margin-top: 0.3rem;
  margin-left: 4%;
  padding: 0 0.08rem;
  border: 0.02rem solid #e6e6e6;
  border-radius: 0.06rem;
  line-height: 0.66rem;
  text-align: center;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.city-item {
  height: 0.88rem;
  line-height: 0.88rem;
  margin-left: 0.3rem;
  border-bottom: 0.02rem solid #c8c7cc;

  &:last-child {
    border: none;
  }
}
</style>
